home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14439
/
14439.xpi
/
chrome
/
tabber.jar
/
content
/
opentabsrelative.js
< prev
next >
Wrap
Text File
|
2009-11-11
|
4KB
|
106 lines
/*
Open tabs to the right of current tab
Reference: Open Tabs Relative by John Mellor
Latest revisions by Frank Yan - 2009.10.05
<license>
Copyright (c) 2006 John Mellor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
</license>
*/
window.addEventListener("load", function(event) {
// Globals
window.tabsopenrelative_nextTabShift = 1;
window.tabsopenrelative_nextIsRelative = null;
// Reset shift upon switching tabs
getBrowser().mTabContainer.addEventListener("select", function() { tabsopenrelative_nextTabShift = 1; }, false);
// Decrement shift if tab closed in shift region (recent children of current tab)
gBrowser.mTabContainer.addEventListener("DOMNodeRemoved", function(event) {
try {
var index = event.target._tPos;
if (index && gBrowser.mTabContainer.selectedIndex < index && gBrowser.mTabContainer.selectedIndex + tabsopenrelative_nextTabShift > index)
tabsopenrelative_nextTabShift--;
}
catch (ex) {}
}, false);
// Mark certain tab sources as always related to current tab
var relatedTabSources = [
'nsContextMenu.prototype.openLinkInTab',
'nsContextMenu.prototype.openFrameInTab',
'nsContextMenu.prototype.viewBGImage',
'nsContextMenu.prototype.addDictionaries',
'nsContextMenu.prototype.viewMedia'
];
relatedTabSources.forEach(function (fname) {
if (fname.indexOf('Frame') == -1)
eval(fname + "=" + eval(fname + ".toString()").replace(
'{', // First '{'
'{ tabsopenrelative_nextIsRelative = true;'
).replace(
/\}$/, // Last '}'
'tabsopenrelative_nextIsRelative = null; }'
));
else
eval(fname + "=" + eval(fname + ".toString()").replace('{', '{ tabsopenrelative_nextIsRelative = true;'));
});
// Mark Javascript popups are related to current tab, but links from external applications as unrelated
eval("nsBrowserAccess.prototype.openURI = " + nsBrowserAccess.prototype.openURI.toString().replace(
'var newTab',
'tabsopenrelative_nextIsRelative = !isExternal; \
$&'
));
// Make final decision as to whether new tab is related to current tab or not,
// using call stack if necessary, then move it if appropriate
eval("gBrowser.addTab = " + gBrowser.addTab.toString().replace(
'if (t.previousSibling.selected)',
'if (tabsopenrelative_nextIsRelative === null) { \
/* Always open relative unless addTab was called from a few known functions, \
* which move the tab themselves */ \
const lvl1NonRelativeSources = ["sss_undoCloseTab", "sss_restoreWindow"]; \
if (arguments.callee.caller \
&& lvl1NonRelativeSources.indexOf(arguments.callee.caller.name) != -1) \
tabsopenrelative_nextIsRelative = false; \
else \
tabsopenrelative_nextIsRelative = true; \
} \
/* check preference */ \
if (!getBoolPref("tabberwocky.opentabsrelative")) \
tabsopenrelative_nextIsRelative = false; \
if (tabsopenrelative_nextIsRelative) { \
this.moveTabTo(t, this.mCurrentTab._tPos + (getBoolPref("tabberwocky.opentabsrelative.reverse") ? 1 : tabsopenrelative_nextTabShift)); \
tabsopenrelative_nextTabShift++; \
} \
tabsopenrelative_nextIsRelative = null; \
$&'
));
}, false);